<?php

namespace app\api\model\questions;

use app\api\model\Models;
use think\db\Query;
use app\api\traits\model\questions\Question as QuestionTraits;

class Question extends Models
{
    use QuestionTraits;

    /*
     * 定义全局的查询范围
     * @var array
     */
    protected $globalScope = ['noDisplay'];

    /**
     * 根据考试类型获取题目
     * @param Query $query
     * @param int $type
     * @return void
     */
    public function scopeType( Query $query, int $type )
    {
        $query->where('examination_type', $type);
    }

    /**
     * 根据不同的考试类型获取题目
     * @param Query $query
     * @param int $category
     * @return void
     */
    public function scopeCategory( Query $query, int $category )
    {
        $query->where('category', $category);
    }

    /**
     * 设置全局不显示字段
     * @param Query $query
     * @return void
     */
    public function scopeNoDisplay( Query $query )
    {
        $query->field('recommend,create_at,update_at', true);
    }

}
